package com.xinxin.leetcode.problem204;

import java.util.Arrays;

/**
 * @author ShiXinXin
 * @date 2019-08-29 16:26
 */
class Solution {
    public int countPrimes(int n) {
        if (n < 2) {
            return 0;
        }
        boolean[] primes = new boolean[n];
        Arrays.fill(primes, true);
        primes[0] = primes[1] = false;
        for (int i = 2; i < n; i++) {
            if (primes[i]) {
                for (int j = 2; i * j < n; j++) {
                    primes[i * j] = false;
                }
            }
        }
        int sum = 0;
        for (boolean prime : primes) {
            if (prime) {
                sum++;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        int res = new Solution().countPrimes(12);
        System.out.println(res);
    }
}